var e = require;
var t = module;
var o = exports;
var Adv_skd=require("./Adv_skd");
Object.defineProperty(o, "__esModule", {value: !0});
var n = e("NotifyEventType"),
    a = e("GlobalParams"),
    i = e("AudioManager"),
    r = e("ModuleUI"),
    s = e("CommonHelper"),
    l = e("Game"),
    c = e("UIManager"),
    d = e("AD"),
    h = e("Toast"),
    _ = e("task_item_info"),
    u = cc._decorator,
    p = u.ccclass,
    m = u.property,
    f = (function (e) {
        function t() {
            var t = (null !== e && e.apply(this, arguments)) || this;
            return (
                (t.task_content_view = null),
                (t.task_node_item = null),
                (t.now_schedule_num = null),
                (t.now_schedule_bar = null),
                (t.box_info_node = null),
                (t.award_info_ndoe = null),
                (t.btn_node_view = null),
                (t.box_node = null),
                (t.box_info_name = ["金币", "钻石", "随机碎片", "复活币", "英雄体验卡"]),
                (t.schedule_num = 0),
                (t.open_box_index = 0),
                t
            );
        }
        return (
            __extends(t, e),

             (t.prototype.onDisable = function () {
            
                Adv_skd.default.instance.hideBannerAd();
                Adv_skd.default.instance.hideGridAdLeft();
                Adv_skd.default.instance.hideGridAdRight();
                Adv_skd.default.instance.hideGridAdTop();
                Adv_skd.default.instance.hideGridAdLeftOne();
                Adv_skd.default.instance.hideGridAdRightOne();
                Adv_skd.default.instance.hideGridAdButtom();

            }),

            (t.prototype.initView = function () {

                Adv_skd.default.instance.hideBannerAd();
                Adv_skd.default.instance.hideGridAdLeft();
                Adv_skd.default.instance.hideGridAdRight();
                Adv_skd.default.instance.hideGridAdTop();
                Adv_skd.default.instance.hideGridAdLeftOne();
                Adv_skd.default.instance.hideGridAdRightOne();
                Adv_skd.default.instance.hideGridAdButtom();
                Adv_skd.default.instance.showGridAdLeftOne();
                Adv_skd.default.instance.showGridAdRightOne();
                Adv_skd.default.instance.showInterstitialAd();

                e.prototype.initView.call(this), (this.box_info_node.active = !1);
                for (var t = l.default.task_info, o = 0; o < t.length; o++) {
                    var n = cc.instantiate(this.task_node_item);
                    (n.active = !0), n.getComponent(_.default).showTaskInfo(o), n.setParent(this.task_content_view);
                }
                this.showTaskSchedule();
            }),
            (t.prototype.addEvent = function () {
                this.attachEvent(n.default.SEND_PLAYER_GET_TASK_AWARD, this.showTaskSchedule, this);
            }),
            (t.prototype.OnClick = function (t) {
                var o = this;
                e.prototype.OnClick.call(this, t);
                var r = t.node.name;
                switch (r) {
                    case "back_btn":
                        this.emitEvent(n.default.SEND_BOX_PORTAL_INFO, !0), this.node.destroy();
                        break;
                    case "box0":
                    case "box1":
                    case "box2":
                    case "box3":
                    case "box4":
                        (this.open_box_index = Number(s.default.getNameType(r, "box"))),
                            0 == a.GlobalParams.PlayerTaskInfo.value.box_award[this.open_box_index]
                                ? this.showBoxInfo()
                                : h.default.showNewToast("已领取该奖励！");
                        break;
                    case "box_back_btn":
                        this.box_info_node.active = !1;
                        break;
                    case "get_btn":
                    case "double_btn":
                        var _ = function () {
                            for (
                                var e = l.default.task_active[o.open_box_index], t = "double_btn" == r ? 2 : 1, i = 0;
                                i < e.award_type.length;
                                i++
                            )
                                if (e.award_type[i] < 2)
                                    cc.find("UIManager")
                                        .getComponent(c.default)
                                        .addCoinAni(e.award_num[i] * t, e.award_type[i]);
                                else if (2 == e.award_type[i]) {
                                    var d = s.default.getRandomInt(0, 4),
                                        h = a.GlobalParams.PlayerDowerInfo.value;
                                    (h.debris[d] += e.award_num[i] * t), (a.GlobalParams.PlayerDowerInfo.value = h);
                                } else if (3 == e.award_type[i]) {
                                    var _ = a.GlobalParams.PlayerInfo.value,
                                        u = Number(_.revive);
                                    (u += e.award_num[i] * t),
                                        (_.revive = u),
                                        (a.GlobalParams.PlayerInfo.value = _),
                                        o.emitEvent(n.default.UPDATE_HAVE_REVIVE_NUMBER);
                                } else if (4 == e.award_type[i]) {
                                    var p = a.GlobalParams.playerSkinInfo.value;
                                    (p.have.taste_card += e.award_num[i] * t),
                                        (a.GlobalParams.playerSkinInfo.value = p),
                                        o.emitEvent(n.default.UPDATE_HAVE_TASTE_CARD_NUMBER);
                                }
                            var m = a.GlobalParams.PlayerTaskInfo.value;
                            (m.box_award[o.open_box_index] = 1),
                                (a.GlobalParams.PlayerTaskInfo.value = m),
                                o.showOpenBox(),
                                (o.box_info_node.active = !1);
                        };
                        "double_btn" == r
                            ? d.default.getInstance().showVideo(function (e) {
                                  i.default.playGameBGM(), e == d.ResultEnum.Success && _();
                              })
                            : _();
                }
            }),
            (t.prototype.showTaskSchedule = function () {
                this.schedule_num = 0;
                for (var e = a.GlobalParams.PlayerTaskInfo.value, t = 0; t < e.schedule.length; t++)
                    -1 == e.schedule[t] && (this.schedule_num += l.default.task_info[t].active);
                (this.now_schedule_num.string = this.schedule_num + ""),
                    (this.now_schedule_bar.width = (1100 * this.schedule_num) / 500),
                    this.showOpenBox();
            }),
            (t.prototype.showBoxInfo = function () {
                for (
                    var e = l.default.task_active[this.open_box_index], t = 0;
                    t < this.award_info_ndoe.childrenCount;
                    t++
                ) {
                    var o = e.award_type.indexOf(t);
                    (this.award_info_ndoe.children[t].active = -1 != o),
                        -1 != o &&
                            (this.award_info_ndoe.children[t].children[1].getComponent(cc.Label).string =
                                this.box_info_name[t] + "x" + e.award_num[o]);
                }
                (this.btn_node_view.children[0].getComponent(cc.Button).interactable =
                    this.schedule_num >= 100 * (this.open_box_index + 1)),
                    (this.btn_node_view.children[1].active = this.schedule_num >= 100 * (this.open_box_index + 1)),
                    (this.box_info_node.active = !0),
                    d.default.getInstance().showInter();
            }),
            (t.prototype.showOpenBox = function () {
                for (var e = a.GlobalParams.PlayerTaskInfo.value, t = 0; t < 5; t++) {
                    var o = this.box_node.children[t];
                    (o.children[0].active = this.schedule_num >= 100 * (t + 1) && 0 == e.box_award[t]),
                        (o.children[1].active = 1 != e.box_award[t]),
                        (o.children[2].active = 1 == e.box_award[t]);
                }
            }),
            __decorate([m(cc.Node)], t.prototype, "task_content_view", void 0),
            __decorate([m(cc.Node)], t.prototype, "task_node_item", void 0),
            __decorate([m(cc.Label)], t.prototype, "now_schedule_num", void 0),
            __decorate([m(cc.Node)], t.prototype, "now_schedule_bar", void 0),
            __decorate([m(cc.Node)], t.prototype, "box_info_node", void 0),
            __decorate([m(cc.Node)], t.prototype, "award_info_ndoe", void 0),
            __decorate([m(cc.Node)], t.prototype, "btn_node_view", void 0),
            __decorate([m(cc.Node)], t.prototype, "box_node", void 0),
            __decorate([p], t)
        );
    })(r.default);
o.default = f;
